package org.wms;

import dev.langchain4j.community.model.dashscope.QwenChatModel;
import dev.langchain4j.community.model.dashscope.WanxImageModel;
import dev.langchain4j.data.image.Image;
import dev.langchain4j.model.chat.ChatLanguageModel;
import dev.langchain4j.model.ollama.OllamaChatModel;
import dev.langchain4j.model.ollama.OllamaModel;
import dev.langchain4j.model.openai.OpenAiChatModel;
import dev.langchain4j.model.output.Response;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.core.env.Environment;

/**
 * @author : 阿盛哟
 * @description :
 * @createDate : 2025/4/29 21:05
 */

@SpringBootTest(classes = XiaozhiApp.class)
public class LLMTest {
    /**
     * 测试openai的chatmodel
     */
    @Test
    public void testGPTDemo() {
        try {
            OpenAiChatModel model = OpenAiChatModel.builder()
                    .baseUrl("http://langchain4j.dev/demo/openai/v1")
                    .apiKey("demo")
                    .modelName("gpt-4o-mini")
                    .build();

            String answer = model.chat("你是谁");
            System.out.println("Answer: " + answer);

        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    /**
     * 测试springboot下的openai的chatmodel
     */
    @Autowired
    private  OpenAiChatModel openAiChatModel;
//    private ChatLanguageModel chatLanguageModel;
    @Test
    public void testSpringBoot() {
        String answer = openAiChatModel.chat("你是谁");
        System.out.println(answer);
    }

    /**
     * 测试ollama的chatmodel
     */
    @Autowired
    private OllamaChatModel ollamaChatModel;
    @Test
    public void testOllama() {
        String answer = ollamaChatModel.chat("你是谁");
        System.out.println(answer);
    }


    /**
     * 通义千问大模型
     */
    @Autowired
    private QwenChatModel qwenChatModel;
    @Test
    public void testDashScopeQwen() {
        //向模型提问
        String answer = qwenChatModel.chat("你好");
        //输出结果
        System.out.println(answer);
    }

    /**
     * 测试通义千问大模型的图片生成
     */
    @Test
    public void testDashScopeWanx(){
        WanxImageModel wanxImageModel = WanxImageModel
                .builder()
                .modelName("wanx2.0-t2i-turbo")
                .apiKey(System.getenv("TONGYI_API_KEY"))
                .build();
        Response<Image> response = wanxImageModel.generate("奇幻森林精灵：在一片弥漫着轻柔薄雾的\n" +
                "古老森林深处，阳光透过茂密枝叶洒下金色光斑。一位身材娇小、长着透明薄翼的精灵少女站在一朵硕大的蘑菇上。她\n" +
                "有着海藻般的绿色长发，发间点缀着蓝色的小花，皮肤泛着珍珠般的微光。身上穿着由翠绿树叶和白色藤蔓编织而成的\n" +
                "连衣裙，手中捧着一颗散发着柔和光芒的水晶球，周围环绕着五彩斑斓的蝴蝶，脚下是铺满苔藓的地面，蘑菇和蕨类植\n" +
                "物丛生，营造出神秘而梦幻的氛围。");
        System.out.println(response.content().url());
    }




    /**
     * 测试环境变量
     */
    @Autowired
    private Environment env;

    @Test
    void printEnv() {
        String apiKey = env.getProperty("DEEP_SEEK_API_KEY");
        System.out.println("DEEP_SEEK_API_KEY: " + apiKey); // 如果输出 null，说明环境变量未生效
    }
}